//
//  UIScrollView+Helper.m
//  SheMeasured
//
//  Created by ddkj on 2019/5/8.
//  Copyright © 2019 xmddkj. All rights reserved.
//

#import "UIScrollView+Helper.h"
#import "CustomRefreshHeader.h"

@implementation UIScrollView (Helper)

- (void)headerRefreshingWithTarget:(id)target selector:(SEL)aSelector {
    CustomRefreshHeader *header = [CustomRefreshHeader headerWithRefreshingTarget:target refreshingAction:aSelector];
    self.mj_header = header;
}

- (void)footerRefreshingWithTarget:(id)target selector:(SEL)aSelector {
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:target refreshingAction:aSelector];
//    footer.automaticallyRefresh = NO;
    footer.refreshingTitleHidden = YES;
    self.mj_footer = footer;
}

- (void)endRefreshing {
    [self.mj_header endRefreshing];
    [self.mj_footer endRefreshing];
}

- (void)endRefreshingWithMore:(BOOL)more {
    if (self.mj_header.isRefreshing) {
        [self.mj_header endRefreshing];
    }
    [self footerEndRefreshingWithMore:more];
}

- (void)footerEndRefreshingWithMore:(BOOL)more {
    if (more) {
        [self.mj_footer endRefreshing];
        [self.mj_footer resetNoMoreData];
    } else {
        [self.mj_footer endRefreshingWithNoMoreData];
    }
}

@end
